<template>
    <div style="padding:20px;" class="personal">
        <span style="color:#8c939d;">请认真填写您的邮箱地址，方便我们及时准确的发送资料，谢谢！</span>
        <br>

        <x-input style="margin:1rem 0;" title="邮箱" v-model="email" placeholder="请输入邮箱地址" is-type="email"></x-input>

        <x-button type="primary" @click.native="sb" style="top:10px;">领取资料</x-button>
    </div>
</template>
<script>
import { XButton, XInput, Group } from 'vux';
import { sendContentForEmail, getUserEmail } from '@/api/activity';
export default {
    components: {
        XButton,
        XInput,
        Group,
    },
    data() {
        return {
            email: null,
            activityId: this.$route.query.activityId,
            //微信openid
            openId: this.$route.query.openid,
            //获取企业id
            eid: this.$route.query.eid,
            //获取微信id
            wxid: this.$route.query.wxid,
        }
    },
    methods: {
        sb() {
            // 验证邮箱格式
            var reg = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/
            if (!reg.test(this.email)) {
                this.$vux.toast.show({
                    type: 'cancel',
                    time: 2000,
                    text: '邮箱地址<br/>格式不正确'
                })
                return false
            }
            this.$vux.loading.show({
                text: 'Loading'
            })
            sendContentForEmail(this.activityId, this.email).then(res => {
                this.$vux.loading.hide()
                this.$vux.toast.show({
                    type: 'success',
                    width:'70%',
                    time: 2000,
                    text: '邮箱服务器已收到您的发送指令，<br/>请稍后查看您的邮箱，谢谢！'
                })
            }).catch(() => {
                this.$vux.loading.hide()
                this.$vux.toast.show({
                    text: '领取失败',
                    type: 'cancel'
                })
            })
        }
    },
    created() {
        getUserEmail().then(res => {
            if (res.user) {
                this.email = res.user.email
            }
        })
    }
}
</script>
<style scoped>

</style>